package com.example.demo.core;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
public class Swagger2 {
    @Value("${spring.swagger.enable}")
    private boolean swaggerShow;

    @Bean
    public Docket createRestApi(){

        ApiInfo apiInfo = new ApiInfoBuilder()
                .title("spring boot + swagger 创建API文档（First）")
                .description("restful 风格的api帮助文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .contact(new Contact("chenhegang", "", ""))
                .version("1.0")
                .build();

        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .enable(swaggerShow)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.any())
                .build();
    }

}
